package com.bob.demo.system.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.bob.demo.system.dao.UserRepository;
import com.bob.demo.system.model.Menu;
import com.bob.demo.system.model.Tree;
import com.bob.demo.system.service.IUserService;

@RequestMapping("admin")
@Controller
public class SystemController extends BaseController {


	@Autowired
    private UserRepository userRepository;
	
	@Autowired
    private IUserService userService;
	
	
	@Value("${test.msg}")
	private String msg;
	
	@GetMapping({ "/index" })
	public String index(HttpServletRequest request, HttpServletResponse response,Model model) {
		System.err.println("888888888888");
		List<Tree<Menu>> menus = userService.listMenuTree(getUserId());
		model.addAttribute("menus", menus);
		model.addAttribute("username", getUsername());
//		FileDO fileDO = fileService.get(getUser().getPicId());
//		if(fileDO!=null&&fileDO.getUrl()!=null){
//			if(fileService.isExist(fileDO.getUrl())){
//				model.addAttribute("picUrl",fileDO.getUrl());
//			}else {
//				model.addAttribute("picUrl","/img/photo_s.jpg");
//			}
//		}else {
//			model.addAttribute("picUrl","/img/photo_s.jpg");
//		}
//		model.addAttribute("username", getUser().getUsername());
		return "amazeui/admin/index";
	}
	
	@GetMapping({"/main"})
	public String main(HttpServletRequest request, HttpServletResponse response,Model model) {
		System.err.println("666");
		return "amazeui/admin/main";
	}

}
